import { Component, OnInit } from '@angular/core';
import { ApiService } from '../../../../providers/ApiPro.service';
import { ActivatedRoute } from '@angular/router';
import { HybCar, parts, HybCarUserHistoryDto } from '../HuoRestmp.model';



@Component({
  selector: 'app-ResCarInfo',
  templateUrl: './ResCarInfo.component.html',
  styleUrls: ['./ResCarInfo.component.scss']
})
export class ResCarInfoComponent implements OnInit {
  public data = [];
  public _total = 0;
  public pageIndex = 1;
  public carinfo: HybCar = new HybCar();
  public parts: parts = new parts();
  constructor(
    public apiService: ApiService,
    private route: ActivatedRoute
  ) { }

  ngOnInit() {
    this.getId();
  }

  getId(){
    this.route.params.subscribe((params) => {
           this.load(params['id']);
           this.parts.carId = params['id'];
           this.loadHis();
       });
 }

 load(id){
  let url = "car/findinfo"
  this.apiService.get(url,{"carId":id})
    .then(res =>{
      this.carinfo = res.result;
    })
  }

  loadHis(){
    let url ="car/findcarhistory";
    this.apiService.get(url,this.parts)
    .then(res =>{
      console.log(res);
      this.data = res.result;
      this._total = res.result;
    })
  }

  resetIndex(e) {
    this.parts.setPage(e);
    this.loadHis();
}


}
